package controlLayer;

import java.util.List;
import java.util.ArrayList;

import modelLayer.Class;
import modelLayer.Room;
import modelLayer.Schedule;
import modelLayer.Staff;

public class ConflictCtrl {
	
	private ScheduleCtrl sc = new ScheduleCtrl();
	private ClassCtrl cc = new ClassCtrl();
	private List<Class> conflictStaffClasses = new ArrayList<>();
	private List<Class> conflictRoomClasses = new ArrayList<>();
	private List<Schedule> blockNoSchedules;
	
	public ConflictCtrl () {
		
	}
	
	public List<Class> getClasses () {
		
		return cc.allClasses();
		
	}
	
	public void importSchedules (int blockNo) {
		
		blockNoSchedules = sc.schedulesAtBlockNo(blockNo);
		
	}
	
	public boolean checkStaffConflict (int blockNo, Staff staff) {
		
		boolean conflict = false;
		
		for (Schedule s: blockNoSchedules) {
			
			try {
			
				if (s.getBlockNo() == blockNo && s.getTeachingBlock().getStaff().getID() == staff.getID()) {
				
					conflictStaffClasses.add(s.getCl());
				
					conflict = true;
				
				}
			
			}
			catch (Exception e) {
				System.out.println("Exception: " + e);
			}
			
		}
		
		return conflict;
		
	}
	
	public boolean checkRoomConflict (int blockNo, Room room) {
		
		boolean conflict = false;
		
		for (Schedule s: blockNoSchedules) {
			
			try {
				if (s.getBlockNo() == blockNo && s.getTeachingBlock().getRoom().getID() == room.getID()) {
				
					conflictRoomClasses.add(s.getCl());
				
					conflict = true;
				
				}
			}
			catch (Exception e) {
				System.out.println("Exception: " + e);
			}
			
		}
		
		return conflict;
		
	}

	public List<Class> getConflictStaffClasses() {
		return conflictStaffClasses;
	}
	
	public List<Class> getConflictRoomClasses() {
		return conflictRoomClasses;
	}
}
